import { asyncRoutes, constantRoutes } from '@/router/index'

const state = {
  routes: []
}

const mutations = {
  setRoutes(state, routes) {
    state.routes = [...constantRoutes, ...routes]
  }
}

const actions = {
  filterRoutes(context, menus) {
    const routes = asyncRoutes.filter(item => {
      return menus.includes(item.code)
    })
    context.commit('setRoutes', routes)
    return routes
  }
}

export default {
  namespaced: true, // 命名空间
  state,
  mutations,
  actions
}
